package com.adpython.dao.jdoDao;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.Query;

import com.adpython.dao.PageTabsJpaDao;
import com.adpython.domain.PageTabs;
import com.adpython.jpa.EMF;

public class PageTabsJpaDaoImpl implements PageTabsJpaDao{
	
	private EntityManager getEntityManager() {
		return EMF.get().createEntityManager();
	}
	
	public void save(PageTabs tab){
		getEntityManager().persist(tab);
	}
	
	public void remove(PageTabs tab){
		tab=getEntityManager().getReference(PageTabs.class,tab.getId());
		getEntityManager().remove(tab);
	}
	
	public PageTabs update(PageTabs tab){
		PageTabs result=getEntityManager().merge(tab);
		return result;
	}
	
	public PageTabs findById(Long id){
		PageTabs instance = getEntityManager().find(PageTabs.class, id);
		return instance;
	}
	
	public List<PageTabs> findAll(){
		Query query = getEntityManager().createQuery("select p from "+PageTabs.class.getName()+" p order by p.rank");
		return query.getResultList();
	}
}
